﻿using System;
using System.Collections;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Connection;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;

namespace Me.Prettyprint.Cassandra.Model
{
    /// <summary>
    /// Default implementation of CounterSlice interface. The class converts the thrift
    /// CounterColumn to hector HCounterColumn
    /// </summary>
    /// <typeparam name="N"></typeparam>
    public class CounterSliceImpl<N> : CounterSlice<N>
    {
        public CounterSliceImpl(List<CounterColumn> tColumns, Serializer<N> nameSerializer)
        {
            if (tColumns == null || nameSerializer == null)
            {
                throw new NullReferenceException("CounterColumn and NameSerializer cannot be null");
            }
            ColumnsMap = new Dictionary<N, HCounterColumn<N>>(tColumns.Count);
            List<HCounterColumn<N>> list = new List<HCounterColumn<N>>(tColumns.Count);
            foreach (CounterColumn c in tColumns)
            {
                HCounterColumn<N> column = new HCounterColumnImpl<N>(c, nameSerializer);
                ColumnsMap[column.GetName()] = column;
                list.Add(column);
            }
            Columns = list;
        }
        protected Dictionary<N, HCounterColumn<N>> ColumnsMap
        {
            get;
            set;
        }
        public List<HCounterColumn<N>> Columns
        {
            get;
            protected set;
        }
        public HCounterColumn<N> GetColumnByName(N columnName)
        {
            return ColumnsMap[columnName];
        }
    }
}
